package com.yanqu.road.server.manger.player;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.tradewar.*;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupUnion;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupUser;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.logic.bussiness.player.UserActivityBussiness;
import com.yanqu.road.logic.bussiness.player.UserTradeWarBussiness;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.logic.sort.TradeWarScoreSort;
import com.yanqu.road.logic.sort.TradeWarWantedSort;
import com.yanqu.road.logic.thread.ThreadTaskManger;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.tradewar.team.TradeWarTeamProto;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.patrons.PatronsSimpleCacheMgr;
import com.yanqu.road.server.manger.player.task.AddTradeWarRecordTask;
import com.yanqu.road.server.manger.player.task.ChangeTradeWarScoreTask;
import com.yanqu.road.server.manger.player.task.NotifyBeKillPatronsCountTask;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.logic.pb.TradeWarPb;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.config.battle.BattleResult;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.gameplayer.module.player.TradeWarModule;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.rank.RankMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.*;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class TradeWarMgr extends TempMgr {

	private static Logger logger = LogManager.getLogger(TradeWarMgr.class.getName());

	private static Map<Long, UserTradeWarInfo> userTradeWarInfoMap;

	private static LinkedList<UserTradeWarInfo> userTradeWarInfoList;

	private static TradeWarScoreSort tradeWarScoreSort;

	private static TradeWarWantedSort tradeWarWantedSort;

	private static List<TradeWarNotice> tradeWarNoticeList;

	private static List<TradeWarNotice> needAddNoticeList;

	private static Map<String, TradeWarWanted> tradeWarWantedMap;

	private static LinkedList<TradeWarWanted> finishTradeWarWantedList;

	private static Map<String, Map<Long, List<TradeWarTrackRecord>>> tradeWarTrackRecordMap;

	private static TradeWarProto.TradeWarNoticeListMsg.Builder tradeWarNoticeListMsg;

	private static TradeWarProto.TradeWarWantedListMsg.Builder tradeWarWantedListMsg;

	private static long lastNoticeResetTime;

	private static RandomHelper random = new RandomHelper();

	private static ThreadTaskManger threadTaskManger;

	private static Map<Long, Map<Long, List<TradeWarSimpleNotice>>> tradeWarSimpleNoticeMap;

	@Override
	public boolean init() throws Exception {
		return reload();
	}

	@Override
	public boolean reloadConfig() throws Exception {
		return true;
	}

	@Override
	public boolean stop() {
		return false;
	}

	@Override
	public boolean save() {
		List<TradeWarNotice> tempAddNoticeList;
		synchronized (needAddNoticeList) {
			tempAddNoticeList = new ArrayList<>(needAddNoticeList);
			needAddNoticeList = new ArrayList<>();
		}
		if (tempAddNoticeList.size() > 0) {
			UserTradeWarBussiness.addTradeWarNoticeList(tempAddNoticeList);
		}
		List<TradeWarWanted> tempWantedList = new ArrayList<>(tradeWarWantedMap.values());
		for(TradeWarWanted tradeWarWanted : tempWantedList){
			if(tradeWarWanted.isInsertOption()){
				UserTradeWarBussiness.addTradeWarWanted(tradeWarWanted);
			}else if(tradeWarWanted.isUpdateOption()){
				UserTradeWarBussiness.updateTradeWarWanted(tradeWarWanted);
			}
		}
		tempWantedList = new ArrayList<>(finishTradeWarWantedList);
		for(TradeWarWanted tradeWarWanted : tempWantedList){
			if(tradeWarWanted.isInsertOption()){
				UserTradeWarBussiness.addTradeWarWanted(tradeWarWanted);
			}else if(tradeWarWanted.isUpdateOption()){
				UserTradeWarBussiness.updateTradeWarWanted(tradeWarWanted);
			}
		}
		if(null != tradeWarTrackRecordMap) {
			for (Map<Long, List<TradeWarTrackRecord>> trackRecordMap : tradeWarTrackRecordMap.values()) {
				for(List<TradeWarTrackRecord> trackRecordList : trackRecordMap.values()){
					List<TradeWarTrackRecord> tempTrackList = new ArrayList<>(trackRecordList);
					for(TradeWarTrackRecord trackRecord : tempTrackList) {
						if (trackRecord.isInsertOption()) {
							UserTradeWarBussiness.addTradeWarTrackRecord(trackRecord);
						} else if (trackRecord.isUpdateOption()) {
							UserTradeWarBussiness.updateTradeWarTrackRecord(trackRecord);
						}
					}
				}
			}
		}
		return true;
	}

	@Override
	public boolean reloadData() {
		if(null == threadTaskManger){
			threadTaskManger = new ThreadTaskManger(1, "TradeWarTaskManger");
		}
		tradeWarScoreSort = new TradeWarScoreSort();
		tradeWarWantedSort = new TradeWarWantedSort();
		finishTradeWarWantedList = new LinkedList<>();
		userTradeWarInfoMap = UserTradeWarBussiness.getUserTradeWarInfoMap();
		userTradeWarInfoList = new LinkedList<>(userTradeWarInfoMap.values());
		userTradeWarInfoList.sort(tradeWarScoreSort);
		//通缉
		Map<String, TradeWarWanted> tempTradeWantedMap = UserTradeWarBussiness.getTradeWarWantedMap();
		for(TradeWarWanted data : tempTradeWantedMap.values()){
			if(data.getUseItemId() == 0){
				data.setUseItemId(GameConfig.TRADE_WAR_WANTED_ITEM_ID);
			}
		}
		tradeWarWantedMap = tempTradeWantedMap;

		tradeWarTrackRecordMap = UserTradeWarBussiness.getTradeWarTrackRecordMap();
		initTradeWarWantedMsg();

		//公告
		initTradeWarNoticeList();
		tradeWarNoticeListMsg = TradeWarProto.TradeWarNoticeListMsg.newBuilder();
		needAddNoticeList = new ArrayList<>();
		if (tradeWarNoticeList.size() > 0) {
			initTradeWarNoticeListMsg();
		}
		return true;
	}

	private static void initTradeWarWantedMsg() {
		long nowTime = System.currentTimeMillis() / 1000;
		synchronized (tradeWarWantedMap){
			for(TradeWarWanted tradeWarWanted : tradeWarWantedMap.values()){
				if(tradeWarWanted.getFinishTime() > 0){
					tradeWarWantedMap.remove(tradeWarWanted.getWantedUid());
					finishTradeWarWantedList.addLast(tradeWarWanted);
				}else if(tradeWarWanted.getFinishTime() == 0 && (nowTime - tradeWarWanted.getWantedTime() > GameConfig.TRADE_WAR_WANTED_TIME
					|| isTrackFull(tradeWarWanted.getWantedUid()))){
					if(nowTime - tradeWarWanted.getWantedTime() > GameConfig.TRADE_WAR_WANTED_TIME){
						tradeWarWanted.setFinishTime(tradeWarWanted.getWantedTime());
						tradeWarWantedMap.remove(tradeWarWanted.getWantedUid());
						finishTradeWarWantedList.addLast(tradeWarWanted);
					}else if(isTrackFull(tradeWarWanted.getWantedUid())){
						tradeWarWanted.setFinishTime(nowTime);
						tradeWarWantedMap.remove(tradeWarWanted.getWantedUid());
						finishTradeWarWantedList.addLast(tradeWarWanted);
					}
				}
			}
			finishTradeWarWantedList.sort(tradeWarWantedSort);
			while (finishTradeWarWantedList.size() > GameConfig.TRADE_WAR_MAX_FINISH_WANTED_COUNT){
				finishTradeWarWantedList.removeFirst();
			}
		}
		List<TradeWarWanted> tempWantedList = new ArrayList<>(finishTradeWarWantedList);
		tempWantedList.addAll(tradeWarWantedMap.values());
		tradeWarWantedListMsg = TradeWarPb.parseTradeWarWantedListMsg(tempWantedList);
	}

	public static UserTradeWarInfo getUserTradeWarInfo(long userId){
		return userTradeWarInfoMap.get(userId);
	}

	public static void setUserTradeWarInfo(UserTradeWarInfo userTradeWarInfo){
		if(null != userTradeWarInfo){
			synchronized (userTradeWarInfoMap){
				userTradeWarInfoMap.put(userTradeWarInfo.getUserId(), userTradeWarInfo);
				synchronized (userTradeWarInfoList){
					for(UserTradeWarInfo info : userTradeWarInfoList){
						if(info.getUserId() == userTradeWarInfo.getUserId()){
							userTradeWarInfoList.remove(info);
							break;
						}
					}
					userTradeWarInfoList.add(userTradeWarInfo);
					userTradeWarInfoList.sort(tradeWarScoreSort);
				}
			}
		}
	}

	/**
	 * 商战分数变更
	 * @param userId
	 * @param addScore
	 * @return
	 */
	public static UserTradeWarInfo changeTradeWarScore(long userId, int addScore) {
		UserTradeWarInfo userTradeWarInfo = getUserTradeWarInfo(userId);
		if(null != userTradeWarInfo) {
			synchronized (userTradeWarInfoList) {
				userTradeWarInfo.setScore(userTradeWarInfo.getScore() + addScore);
				userTradeWarInfo.setModifyTime(System.currentTimeMillis() / 1000);
				userTradeWarInfoList.sort(tradeWarScoreSort);
			}
			RankMgr.changeUserRank(eBigRankType.Normal.getValue(), userId, BigInteger.valueOf(userTradeWarInfo.getScore()), eRankType.TradeWarScore.getValue(), "");
			GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
			if(null != player){
				player.getModule(TradeWarModule.class).syncUserTradeWarInfo();
				//商战积分冲榜
				player.notifyListener(eGamePlayerEventType.TradeWarScoreRiseRank.getValue(), addScore);
				player.notifyListener(eGamePlayerEventType.UnionTradeWarScoreRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL,
						BigInteger.valueOf(addScore), player.getUserInfo().getUnionUid()));
			}else {
				UserTradeWarBussiness.updateUserTradeWarInfo(userTradeWarInfo);
				List<ActivityInfo> activityInfoList = NormalActivityMgr.getTradeWarScoreRiseRankActivityList();
				for(ActivityInfo activityInfo : activityInfoList){
					List<ActivityConditionInfo> activityConditionInfoList = NormalActivityMgr.getActivityConditionInfoList(activityInfo.getActivityId());
					UserActivityConditionData userActivityConditionData = null;
					if(null != activityConditionInfoList && activityConditionInfoList.size() > 0){
						userActivityConditionData = UserActivityBussiness.getUserActivityConditionData(activityInfo.getActivityId(), userId);
						if(null == userActivityConditionData){
							userActivityConditionData = NormalActivityMgr.initUserActivityConditionData(userId, UserMgr.getNickName(userId), BigInteger.valueOf(addScore),
									activityInfo.getActivityId(), activityConditionInfoList.get(0).getConditionId(), activityConditionInfoList.get(0).getType());
							UserActivityBussiness.addUserActivityConditionData(userActivityConditionData);
						}else {
							userActivityConditionData.setValue(userActivityConditionData.getValue().add(BigInteger.valueOf(addScore)));
							UserActivityBussiness.updateUserActivityConditionData(userActivityConditionData);
						}
					}
					if(null != userActivityConditionData) {
						if(activityInfo.getType() == eActivityType.RankActivity.getValue()) {
							RankMgr.changeActivityRank(activityInfo.getActivityId(), userId, userActivityConditionData.getValue(), userActivityConditionData.getParam());
						}else if(activityInfo.getType() == eActivityType.UnionRankActivity.getValue()){
							UserInfo userInfo = UserMgr.getUserInfo(userId);
							if(null != userInfo) {
								String unionUid = userInfo.getUnionUid();
								if(!StringUtils.isNullOrEmpty(unionUid)) {
									UnionActivityMgr.changeUnionActivityValue(activityInfo.getActivityId(), unionUid, userId, userActivityConditionData, UnionRiseRankArgs.NOTIFY_TYPE_NORMAL);
								}
							}
						}
					}
				}
			}
		}
		return userTradeWarInfo;
	}

	/**
	 * 匹配随机对手
	 */
	public static UserTradeWarInfo findRandomEnemy(long userId) {
		UserTradeWarInfo enemyTradeWarInfo = null;
		synchronized (userTradeWarInfoList) {
			// 列表中只有自己 随机机器人
			if(null == userTradeWarInfoList){
				return null;
			}
			if (userTradeWarInfoList.size() <= 1) {
				return null;
			}
			int index = userTradeWarInfoList.size();
			for(int i = 0; i < userTradeWarInfoList.size(); i++){
				if(userTradeWarInfoList.get(i).getUserId() == userId){
					index = i;
					break;
				}
			}
			// 按照前50 后50来排序
			int startIndex = index - GameConfig.TRADE_WAR_BATTLE_RANDOM_RANK;
			int endIndex = index + GameConfig.TRADE_WAR_BATTLE_RANDOM_RANK;

			if (startIndex < 0) {
				endIndex = (0 - startIndex) + endIndex;
				startIndex = 0;
			}

			if (endIndex > userTradeWarInfoList.size()) {
				endIndex = userTradeWarInfoList.size();
				startIndex = endIndex - GameConfig.TRADE_WAR_BATTLE_RANDOM_RANK;

				if (startIndex < 0) {
					startIndex = 0;
				}
			}

			int loopTimes = 0;
			while (true) {
				int randomIndex = random.next(startIndex, endIndex);
				UserTradeWarInfo tradeWarInfo = userTradeWarInfoList.get(randomIndex);
				if(null != tradeWarInfo){
					if(tradeWarInfo.getUserId() != userId &&
							PatronsSimpleCacheMgr.getUserPatronsSimpleCount(tradeWarInfo.getUserId()) > 0){//不能随机到自己本人，且门客数量大于0
						enemyTradeWarInfo = tradeWarInfo;
						break;
					}
				}
				loopTimes++;
				if(loopTimes > 100){
					break;
				}
			}
		}
		return enemyTradeWarInfo;
	}

	/**
	 * 随机匹配跨服商战对手
	 */
	public static UserTradeWarInfo findCrossRandomEnemy(int activityId, long myUserId, long myServerId) {
		LinkedList<UserTradeWarInfo> dataList = new LinkedList<>();
		List<String> unionList;
		int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, myUserId);
		//从本服拿出
		List<String> tempList = TradeWarActivityMgr.getCrossTradeWarUnionList(activityId,groupId);
		if(null != tempList){
			unionList = new ArrayList<>(tempList);
		}else {
			unionList = new ArrayList<>();
		}
		if(myServerId == GameServer.getInstance().getServerId()){//匹配同区服的
			UserInfo userInfo = UserMgr.getUserInfo(myUserId);
			if(!StringUtils.isNullOrEmpty(userInfo.getUnionUid())) {
				unionList.remove(userInfo.getUnionUid());
			}
		}
		//先拿分组
		UnionActivityGroupUnion unionData = GameUnionActivityGroupMgr.getUnionData(activityId, myUserId);
		if (unionData != null){
			if (unionList.contains(unionData.getUnionUid())){
				unionList.remove(unionData.getUnionUid());
			}
		}

		for(String unionUid : unionList){
			UnionActivityGroupUnion otherUnionData = GameUnionActivityGroupMgr.getUnionData(activityId, unionUid);
			if(null != otherUnionData) {
				for (UnionActivityGroupUser member : otherUnionData.getUserMap().values()) {
					UserTradeWarInfo userTradeWarInfo = getUserTradeWarInfo(member.getUserId());
					if(null != userTradeWarInfo){
						dataList.add(userTradeWarInfo);
					}
				}
			}
		}
		if (dataList.size() < 1) {
			return null;
		}
		int index = random.next(0, dataList.size());
		return dataList.get(index);
	}

	public static void addTradeWarNotice(TradeWarNotice notice) {
		synchronized (tradeWarNoticeList) {
			if(tradeWarNoticeList.size() >= GameConfig.TRADE_WAR_MAX_NOTICE_NUMBER){
				tradeWarNoticeList.remove(0);
			}
			tradeWarNoticeList.add(notice);
			needAddNoticeList.add(notice);
			if(!tradeWarSimpleNoticeMap.containsKey(notice.getUserId())){
				tradeWarSimpleNoticeMap.put(notice.getUserId(), new ConcurrentHashMap<>());
			}
			if(notice.getBattleType() == eTradeWarBattleType.Challenge.getValue()) {
				TradeWarSimpleNotice simpleNotice = initTradeWarSimpleNotice(notice);
				Map<Long, List<TradeWarSimpleNotice>> tempMap = tradeWarSimpleNoticeMap.get(notice.getUserId());
				if (!tempMap.containsKey(notice.getEnemyUserId())) {
					tempMap.put(notice.getEnemyUserId(), new ArrayList<>());
				}
				List<TradeWarSimpleNotice> tempList = tempMap.get(notice.getEnemyUserId());
				tempList.add(simpleNotice);
			}
			initTradeWarNoticeListMsg();
		}
	}

	public static boolean isInNoticeList(long userId){
		synchronized (tradeWarNoticeList){
			for(TradeWarNotice notice : tradeWarNoticeList){
				if(notice.getUserId() == userId){
					return true;
				}
			}
			return false;
		}
	}

	/**
	 * 发布商战通缉
	 * @param player
	 * @param wantedUserId
	 * @return
	 */
	public static int publishTradeWarWanted(GamePlayer player, long wantedUserId, int useItemId){
		if(player.getUserId() == wantedUserId){
			return GameErrorCode.E_TRADE_WAR_CAN_NO_WANTED_SELF;
		}
		UserTradeWarInfo userTradeWarInfo = player.getModule(TradeWarModule.class).getUserTradeWarInfo();
		if(null == userTradeWarInfo){
			return GameErrorCode.E_SYSTEM_NO_OPEN;
		}
		UserInfo wantedUserInfo = UserMgr.getUserInfo(wantedUserId);
		if(null == wantedUserInfo){
			return GameErrorCode.E_USER_NO_FOUND;
		}
		UserTradeWarInfo wantedTradeWarInfo = getUserTradeWarInfo(wantedUserId);
		if(null == wantedTradeWarInfo){
			return GameErrorCode.E_USER_NO_FOUND;
		}
		if(!GoodsMgr.isTradeWarWanted(useItemId)){
			return GameErrorCode.E_TRADE_WAR_NO_WANTED_GOODS;
		}
		Property consume = new Property(useItemId, BigInteger.ONE);
		if(!player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.TradeWar, eLogMoneyType.TradeWarPublishWanted)){
			return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;
		}
		UserInfo userInfo = player.getModule(PlayerModule.class).getUserInfo();

		long wantedScore = wantedTradeWarInfo.getScore();
		TradeWarWanted tradeWarWanted = initTradeWarWanted(wantedUserId, wantedUserInfo, userInfo, wantedScore, useItemId);
		synchronized (tradeWarWantedMap){
			tradeWarWantedMap.put(tradeWarWanted.getWantedUid(), tradeWarWanted);
		}
		//累计被通缉次数
		wantedTradeWarInfo.setTotalBeWantedTimes(wantedTradeWarInfo.getTotalBeWantedTimes() + 1);
		initTradeWarWantedMsg();
		GamePlayer wantedPlayer = GamePlayerMgr.getOnlinePlayer(wantedUserId);
		if(null != wantedPlayer){
			//成就、任务
			wantedPlayer.notifyListener(eGamePlayerEventType.BeWantedTotalTimes.getValue(), wantedTradeWarInfo);
			TradeWarProto.TradeWarWantedNotifyMsg.Builder beWantedMsg = TradeWarPb.parseTradeWarWantedNotifyMsg(true, tradeWarWanted);
			if(null != beWantedMsg) {
				wantedPlayer.sendPacket(Protocol.U_TRADE_WAR_BE_WANTED_NOTICE, beWantedMsg);
			}
		}
		String mailTitle = MultipleLanguageMgr.getContent(MailManager.TRADE_WAR_BE_WANTED_TITLE, wantedUserInfo.getLanguage());
		String mailContent = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.TRADE_WAR_BE_WANTED_CONTENT, wantedUserInfo.getLanguage()),
				DateHelper.getCurrentDateTimeString(tradeWarWanted.getWantedTime() * 1000), userInfo.getNickName());
		MailManager.sendMail(wantedUserId, eMailType.DAILY.getValue(), "", mailContent, mailTitle);
		worldNotifyWanted(tradeWarWanted);
		//累计发布通缉次数
		userTradeWarInfo.setTotalPublishWantedTimes(userTradeWarInfo.getTotalPublishWantedTimes() + 1);
		//成就、任务
		player.notifyListener(eGamePlayerEventType.PublishWantedTotalTimes.getValue(), userTradeWarInfo);
		LogMgr.addLogPublishWanted(player.getUserId(), wantedUserId, PropertyHelper.parsePropertyToString(consume), tradeWarWanted.getWantedTime());
		//聊天窗口发布通缉消息
		WorldMessageMgr.worldNotify(player, eMessageType.TradeWarWanted.getValue(), wantedUserInfo.getNickName());

		DataAnalyticsMgr.trackOreWarWanted(player, tradeWarWanted);

		return 0;
	}

	private static TradeWarWanted initTradeWarWanted(long wantedUserId, UserInfo wantedUserInfo, UserInfo userInfo, long wantedScore, int useItemId) {
		TradeWarWanted tradeWarWanted = new TradeWarWanted();
		tradeWarWanted.setWantedUid(UUIDHelper.randomUUID(String.valueOf(GameServer.getInstance().getServerId())));
		tradeWarWanted.setUserId(userInfo.getUserId());
		tradeWarWanted.setUserBaseInfo(UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()));
		tradeWarWanted.setWantedUserId(wantedUserId);
		tradeWarWanted.setWantedBaseInfo(UserMgr.parseUserBaseInfo(wantedUserInfo, GameServer.getInstance().getServerId()));
		tradeWarWanted.setWantedScore(wantedScore);
		tradeWarWanted.setWantedTime(System.currentTimeMillis() / 1000);
		tradeWarWanted.setBattleTimes(0);
		Property wantedReward = PropertyHelper.parseStringToProperty(GameConfig.TRADE_WAR_WANTED_REWARD);
		GoodsInfo wantedGoods = GoodsMgr.getGoodsById(useItemId);
		if(null != wantedGoods){
			int param1 = wantedGoods.getParamList().get(0).intValue();
			wantedReward.rideProperty(param1);
		}
		tradeWarWanted.setReward(PropertyHelper.parsePropertyToString(wantedReward));
		tradeWarWanted.setScoreReward(false);
		tradeWarWanted.setUseItemId(useItemId);
		tradeWarWanted.setInsertOption();
		return tradeWarWanted;
	}

	/**
	 * 给发布通缉的人发送积分奖励
	 * @param wantedUid
	 */
	public static void sendTrackTradeWarScoreReward(String wantedUid) {
		TradeWarWanted wanted = getTradeWarWanted(wantedUid);
		if(null == wanted){
			wanted = getFinishTradeWarWanted(wantedUid);
			if (null == wanted) {
				return;
			}
		}

		// 已经发了奖励的不管它
		if (wanted.isScoreReward()) {
			return;
		}

		// 已经过期 或者 记录已经达到条件
		if(!isWantedTime(wanted) || isTrackFull(wantedUid)){
			int score = 0; // 商战积分
			int people = 0;
			int moneyScore = 0; // 商战币
			Map<Long, List<TradeWarTrackRecord>> recordMap = getTradeWarTrackRecord(wantedUid);
			if (recordMap != null) {
				for (List<TradeWarTrackRecord> list : recordMap.values()) {
					for (TradeWarTrackRecord tradeWarTrackRecord : list) {
						score += tradeWarTrackRecord.getMyAddScore();
						moneyScore += tradeWarTrackRecord.getTradeWarMoney();
					}
					people += list.size();
				}
			}

			UserInfo userInfo = UserMgr.getUserInfo(wanted.getUserId());
			String rewardStr = "";
			if (score > 0) {
				rewardStr = (GameConfig.GAME_MONEY_TRADE_WAR_SCORE + "=" + moneyScore);
				TradeWarMgr.changeTradeWarScore(userInfo.getUserId(), score);
			}
			long enemyUser = wanted.getWantedUserId();

			String title = MultipleLanguageMgr.getContent(MailManager.TRACK_TRADE_WAR_SCORE_REWORD_TITLE, userInfo.getLanguage());
			String content = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.TRACK_TRADE_WAR_SCORE_REWORD_CONTENT,
					userInfo.getLanguage()), UserMgr.getUserInfo(enemyUser).getNickName(), people, score);
			logger.info("{} {}", userInfo.getUserId(), rewardStr);
			MailManager.sendMail(userInfo.getUserId(), eMailType.DAILY.getValue(), rewardStr, content, title);
			wanted.setScoreReward(true);
		}

	}

	private static void worldNotifyWanted(TradeWarWanted tradeWarWanted){
		TradeWarProto.TradeWarWantedNotifyMsg.Builder wantedMsg = TradeWarPb.parseTradeWarWantedNotifyMsg(false, tradeWarWanted);
		if(null != wantedMsg) {
			for (GamePlayer player : GamePlayerMgr.getCopyPlayerMap().values()) {
				if(player.getUserId() != tradeWarWanted.getWantedUserId()){
					player.sendPacket(Protocol.U_TRADE_WAR_BE_WANTED_NOTICE, wantedMsg);
				}
			}
		}
	}

	public static TradeWarWanted getTradeWarWanted(String wantedUid){
		return tradeWarWantedMap.get(wantedUid);
	}

	public static TradeWarWanted getFinishTradeWarWanted(String wantedUid){
		List<TradeWarWanted> dataList = new ArrayList<>(finishTradeWarWantedList);
		for(TradeWarWanted tradeWarWanted : dataList){
			if(Objects.equals(tradeWarWanted.getWantedUid(), wantedUid)){
				return tradeWarWanted;
			}
		}
		return null;
	}

	/**
	 * 追辑准备
	 * @param player 追辑玩家
	 * @param wantedUid 通缉唯一标识
	 * @return 结果值
	 */
	public static int trackPrepare(GamePlayer player, String wantedUid){
		TradeWarModule tradeWarModule = player.getModule(TradeWarModule.class);
		UserTradeWarInfo userTradeWarInfo = tradeWarModule.getUserTradeWarInfo();
		synchronized (tradeWarWantedMap){
			TradeWarWanted wanted = getTradeWarWanted(wantedUid);
			if(null == wanted){
				return GameErrorCode.E_TRADE_WAR_WANTED_NO_EXIST;
			}
			if(!isWantedTime(wanted)){
				return GameErrorCode.E_TRADE_WAR_WANTED_OVER_TIME;
			}
			int addTimes = 1;
			if(wanted.getUserId() != player.getUserId()) {//自己发布的通缉不判断次数
				int useItemId = wanted.getUseItemId();
				GoodsInfo goodsInfo = GoodsMgr.getGoodsById(useItemId);
				if(null != goodsInfo){
					addTimes = goodsInfo.getParamList().get(0).intValue();
				}
				if (userTradeWarInfo.getDailyTrackTimes() + addTimes > ConfigMgr.getTradeWarTrackTimesByVip(VipMgr.getVipLv(player.getUserInfo().getVipExp()))) {
					return GameErrorCode.E_TRADE_WAR_TRACK_TIMES_OVER;
				}
				// 换掉 判断有多少人打过了 旧的是匹配次数 新版换成已被打的次数	不是自己发布的判断协助追击次数
				if (isHelpUserTrackFull(wantedUid)) {
					return GameErrorCode.E_TRADE_WAR_WANTED_OVER_BATTLE_TIMES;
				}
			} else {
				if (isPublishUserTrackFull(wantedUid)) {
					return GameErrorCode.E_TRADE_WAR_WANTED_OVER_BATTLE_TIMES;
				}
			}

			List<TradeWarTrackRecord> trackList = getTradeWarTrackRecordList(wantedUid, player.getUserId());
			if(null != trackList && trackList.size() >= GameConfig.TRADE_WAR_WANTED_USER_BATTLE_TIMES){
				return GameErrorCode.E_TRADE_WAR_WANTED_TRACK_TIMES_OVER;
			}

			wanted.setBattleTimes(wanted.getBattleTimes() + 1);
			initTradeWarWantedMsg();
			if(wanted.getUserId() != player.getUserId()) {//自己发布的通缉不加次数
				tradeWarModule.addTraceTimes(addTimes);
			}
			return 0;
		}
	}

	/**
	 * 判断是否所有人追击满了
	 */
	public static boolean isTrackFull(String wantedUid) {
		return isHelpUserTrackFull(wantedUid) && isPublishUserTrackFull(wantedUid);
	}


	/**
	 * 判断帮助追击的人数是否满了
	 *
	 * @param wantedUid
	 * @return
	 */
	public static boolean isHelpUserTrackFull(String wantedUid) {
		return getTrackRecordNum(wantedUid) - getPublishTrackRecordNum(wantedUid) >= GameConfig.TRADE_WAR_WANTED_MAX_BATTLE_TIMES;
	}

	/**
	 * 判断发布者是否追击满了
	 *
	 * @param wantedUid
	 * @return
	 */
	public static boolean isPublishUserTrackFull(String wantedUid) {
		return getPublishTrackRecordNum(wantedUid) >= GameConfig.TRADE_WAR_WANTED_USER_BATTLE_TIMES;
	}
	/**
	 * 判断追击人数是否满了
	 * @param wantedUid
	 * @return
	 */
	public static boolean isTrackFull(String wantedUid, int num) {
		return getTrackRecordNum(wantedUid) >= num;
	}


	/**
	 * 检查有没有需要发奖的通缉
	 */
	public static void checkTrackTradeWarScoreReward() {
		List<TradeWarWanted> tempWantedList = new ArrayList<>(tradeWarWantedMap.values());
		for (TradeWarWanted tradeWarWanted : tempWantedList) {
			synchronized (tradeWarTrackRecordMap) {
				// 防止重复发奖
				sendTrackTradeWarScoreReward(tradeWarWanted.getWantedUid());
			}
		}
	}

	/**
	 * 追辑记录
	 * @param player 追辑玩家
	 * @param wantedUid 通缉唯一标识
	 * @param battleResult 追辑结果
	 * @return 记录
	 */
	public static TradeWarTrackRecord trackRecord(GamePlayer player, String wantedUid, BattleResult battleResult) {
		synchronized (tradeWarTrackRecordMap) {
			// 如果超过次数则不添加到追击记录内
			TradeWarWanted tradeWarWanted = getTradeWarWanted(wantedUid);
			if (tradeWarWanted == null) {
				return null;
			}
			long publishUserId = tradeWarWanted.getUserId();
			if (player.getUserId() != publishUserId) {
				if (isHelpUserTrackFull(wantedUid)) {
					return null;
				}
			} else {
				if (isPublishUserTrackFull(wantedUid)) {
					return null;
				}
			}

			List<TradeWarTrackRecord> trackList = getTradeWarTrackRecordList(wantedUid, player.getUserId());
			if(null == trackList){
				trackList = new ArrayList<>();
				if(!tradeWarTrackRecordMap.containsKey(wantedUid)){
					tradeWarTrackRecordMap.put(wantedUid, new ConcurrentHashMap<>());
				}
				if(!tradeWarTrackRecordMap.get(wantedUid).containsKey(player.getUserId())){
					tradeWarTrackRecordMap.get(wantedUid).put(player.getUserId(), trackList);
				}
			}
			UserInfo userInfo = player.getModule(PlayerModule.class).getUserInfo();
			TradeWarTrackRecord trackRecord = initTradeWarTrackRecord(player, wantedUid, battleResult, userInfo);
			trackList.add(trackRecord);
			//只有包括了发布者的全部人都满了才能领取
			if (isTrackFull(wantedUid)) {
				sendTrackTradeWarScoreReward(wantedUid);
			}
			return trackRecord;
		}
	}

	private static TradeWarTrackRecord initTradeWarTrackRecord(GamePlayer player, String wantedUid, BattleResult battleResult, UserInfo userInfo) {
		TradeWarTrackRecord trackRecord = new TradeWarTrackRecord();
		trackRecord.setRecordUid(UUIDHelper.randomUUID(String.valueOf(GameServer.getInstance().getServerId())));
		trackRecord.setWantedUid(wantedUid);
		trackRecord.setUserId(player.getUserId());
		trackRecord.setUserBaseInfo(UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()));
		trackRecord.setKillPatronsCount(battleResult.getKillPatronsCount());
		trackRecord.setLoseScore(battleResult.getEnemyLoseScore());
		trackRecord.setRecordTime(System.currentTimeMillis() / 1000);
		trackRecord.setMyAddScore(battleResult.getMyAddScore());
		Property property = PropertyHelper.parseStringToProperty(battleResult.getReward());
		int tradeWarMoney = property.getCountByGoodsId(GameConfig.GAME_MONEY_TRADE_WAR_SCORE).intValue();
		trackRecord.setTradeWarMoney(tradeWarMoney);
		trackRecord.setInsertOption();
		return trackRecord;
	}

	/**
	 * 是否在通缉时间内
	 * @param wanted
	 * @return
	 */
	public static boolean isWantedTime(TradeWarWanted wanted){
		if(null == wanted){
			return false;
		}
		long nowTime = System.currentTimeMillis() / 1000;
		return nowTime < wanted.getWantedTime() + GameConfig.TRADE_WAR_WANTED_TIME;
	}

	/**
	 * 获取所有被追击个数
	 * @param wantedUid
	 * @return
	 */
	private static int getTrackRecordNum(String wantedUid) {
		int num = 0;
		Map<Long, List<TradeWarTrackRecord>> recordMap = getTradeWarTrackRecord(wantedUid);
		if (recordMap != null) {
			for (List<TradeWarTrackRecord> list : recordMap.values()) {
				num += list.size();
			}
		}
		return num;
	}
	/**
	 * 获取被追击个数(发布者亲自打的)
	 * @param wantedUid
	 * @return
	 */
	private static int getPublishTrackRecordNum(String wantedUid) {
		int num = 0;
		TradeWarWanted tradeWarWanted = getTradeWarWanted(wantedUid);
		long publishUserId = tradeWarWanted.getUserId();
		Map<Long, List<TradeWarTrackRecord>> recordMap = getTradeWarTrackRecord(wantedUid);
		if (recordMap != null) {
			if (recordMap.containsKey(publishUserId)){
				num+=recordMap.get(publishUserId).size();
			}
		}
		return num;
	}

	private static Map<Long, List<TradeWarTrackRecord>> getTradeWarTrackRecord(String wantedUid) {
		return tradeWarTrackRecordMap.get(wantedUid);
	}
	private static List<TradeWarTrackRecord> getTradeWarTrackRecordList(String wantedUid, long userId){
		if(tradeWarTrackRecordMap.containsKey(wantedUid)){
			return tradeWarTrackRecordMap.get(wantedUid).get(userId);
		}
		return null;
	}

	public static void reloadTradeWarNotice() {
		synchronized (tradeWarNoticeList) {
			long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
			if (lastNoticeResetTime < zeroTime) {
				tradeWarNoticeList = new ArrayList<>();
				tradeWarSimpleNoticeMap = new ConcurrentHashMap<>();
				tradeWarNoticeListMsg = TradeWarProto.TradeWarNoticeListMsg.newBuilder();
			}
		}
	}

	public static TradeWarProto.TradeWarNoticeListMsg.Builder getTradeWarNoticeListMsg() {
		return tradeWarNoticeListMsg;
	}

	public static TradeWarProto.TradeWarWantedListMsg.Builder getTradeWarWantedListMsg(GamePlayer player) {
		TradeWarProto.TradeWarWantedListMsg.Builder listMsg = TradeWarProto.TradeWarWantedListMsg.newBuilder();
		for(TradeWarProto.TradeWarWantedTempMsg wantedTempMsg : tradeWarWantedListMsg.clone().getWantedListList()){
			TradeWarProto.TradeWarWantedTempMsg.Builder msg = wantedTempMsg.toBuilder();
			List<TradeWarTrackRecord> tradeList = getTradeWarTrackRecordList(wantedTempMsg.getWantedUid(), player.getUserId());
			if(null == tradeList){
				msg.setTrackTimes(0);
			}else {
				msg.setTrackTimes(tradeList.size());
			}
			listMsg.addWantedList(msg);
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarWantedDetailRespMsg.Builder getTradeWarWantedDetailRespMsg(GamePlayer player, String wantedUid) {
		TradeWarProto.TradeWarWantedDetailRespMsg.Builder respMsg = TradeWarProto.TradeWarWantedDetailRespMsg.newBuilder();
		TradeWarWanted tradeWarWanted = getTradeWarWanted(wantedUid);
		if(null == tradeWarWanted){
			for(TradeWarWanted tempWanted : finishTradeWarWantedList){
				if(Objects.equals(tempWanted.getWantedUid(), wantedUid)){
					tradeWarWanted = tempWanted;
				}
			}
			if(null == tradeWarWanted) {
				respMsg.setRet(GameErrorCode.E_TRADE_WAR_WANTED_NO_EXIST);
				return respMsg;
			}
		}
		TradeWarProto.TradeWarWantedTempMsg.Builder wantedMsg = TradeWarPb.parseTradeWarWantedTempMsg(tradeWarWanted);
		if(null != wantedMsg){
			List<TradeWarTrackRecord> tradeList = getTradeWarTrackRecordList(wantedUid, player.getUserId());
			if(null == tradeList){
				wantedMsg.setTrackTimes(0);
			}else {
				wantedMsg.setTrackTimes(tradeList.size());
			}
			respMsg.setWantedInfo(wantedMsg);
		}
		Map<Long, List<TradeWarTrackRecord>> trackMap = tradeWarTrackRecordMap.get(wantedUid);
		if(null != trackMap){
			for(List<TradeWarTrackRecord> trackList : trackMap.values()){
				if(null != trackList) {
					for (TradeWarTrackRecord trackRecord : trackList) {
						TradeWarProto.TradeWarTrackRecordTempMsg.Builder msg = TradeWarPb.parseTradeWarTrackRecordTempMsg(trackRecord);
						if(null != msg){
							respMsg.addTrackRecordList(msg);
						}
					}
				}
			}
		}
		respMsg.setRet(0);
		return respMsg;
	}

	/**
	 * 对手被击杀门客任务、成就
	 * @param enemyUserId
	 * @param killPatronsCount
	 */
	public static void notifyEnemyBeKillPatronsCount(long enemyUserId, int killPatronsCount){
		if(killPatronsCount > 0) {
			threadTaskManger.addTask(0, new NotifyBeKillPatronsCountTask(enemyUserId, killPatronsCount));
		}
	}

	/**
	 * 处理战斗结果
	 * @param battleResult
	 * @param useItemId
	 * @param warTimes
	 */
	public static void dealBattleResult(BattleResult battleResult, int battleType, int useItemId, int warTimes, String battleUid){
		if(null != battleResult){
			battleResult.setBattleType(battleType);
			battleResult.setUseItemId(useItemId);
			battleResult.setWarTimes(warTimes);
			battleResult.setBattleUid(battleUid);
			if(eTradeWarBattleType.Track.getValue() == battleType){
				TradeWarWanted tradeWarWanted = TradeWarMgr.getTradeWarWanted(battleUid);
				if(null != tradeWarWanted){
					if(0 == tradeWarWanted.getUseItemId()){
						battleResult.setWantedItemId(GameConfig.TRADE_WAR_WANTED_ITEM_ID);
					}else {
						battleResult.setWantedItemId(tradeWarWanted.getUseItemId());
					}
				}
			}
		}
	}

	/**
	 * 增加商战记录任务
	 * @param tradeWarRecord
	 */
	public static void addTradeRecordTask(UserTradeWarRecord tradeWarRecord){
		threadTaskManger.addTask(0, new AddTradeWarRecordTask(tradeWarRecord));
	}

	/**
	 * 变更商战分数，适用于对手，因为对手可能不在线耗时较久
	 * @param userId
	 * @param addScore
	 */
	public static void changeTradeWarScoreTask(long userId, int addScore){
		threadTaskManger.addTask(0, new ChangeTradeWarScoreTask(userId, addScore));
	}

	/**
	 * 获取简略公告信息
	 * @param userId
	 * @param enemyUserId
	 * @return
	 */
	public static List<TradeWarSimpleNotice> getTradeWarSimpleNoticeList(long userId, long enemyUserId){
		Map<Long, List<TradeWarSimpleNotice>> dataMap = tradeWarSimpleNoticeMap.get(userId);
		if(null == dataMap){
			return null;
		}
		List<TradeWarSimpleNotice> dataList = dataMap.get(enemyUserId);
		if(null != dataList){
			return new ArrayList<>(dataList);
		}
		return null;
	}

	/**
	 * 初始化商会公告
	 */
	public static void initTradeWarNoticeList(){
		long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
		List<TradeWarNotice> tempTradeWarNoticeList = UserTradeWarBussiness.getTradeWarNoticeList(zeroTime / 1000);
		List<TradeWarNotice> resultTradeWarNoticeList = new ArrayList<>();
		Map<Long, Map<Long, List<TradeWarSimpleNotice>>> tempTradeWarSimpleNoticeMap = new ConcurrentHashMap<>();
		for(TradeWarNotice tradeWarNotice : tempTradeWarNoticeList){
			if(tradeWarNotice.getBattleType() == eTradeWarBattleType.Challenge.getValue()) {
				TradeWarSimpleNotice simpleNotice = initTradeWarSimpleNotice(tradeWarNotice);
				if (!tempTradeWarSimpleNoticeMap.containsKey(simpleNotice.getUserId())) {
					tempTradeWarSimpleNoticeMap.put(simpleNotice.getUserId(), new ConcurrentHashMap<>());
				}
				Map<Long, List<TradeWarSimpleNotice>> tempMap = tempTradeWarSimpleNoticeMap.get(simpleNotice.getUserId());
				if (!tempMap.containsKey(simpleNotice.getEnemyUserId())) {
					tempMap.put(simpleNotice.getEnemyUserId(), new ArrayList<>());
				}
				List<TradeWarSimpleNotice> tempList = tempMap.get(simpleNotice.getEnemyUserId());
				tempList.add(simpleNotice);
			}
			if(resultTradeWarNoticeList.size() >= GameConfig.TRADE_WAR_MAX_NOTICE_NUMBER){
				resultTradeWarNoticeList.remove(0);
			}
			resultTradeWarNoticeList.add(tradeWarNotice);
		}
		tradeWarNoticeList = resultTradeWarNoticeList;
		tradeWarSimpleNoticeMap = tempTradeWarSimpleNoticeMap;
		lastNoticeResetTime = zeroTime;
	}

	/**
	 * 初始化简略公告实体
	 * @param tradeWarNotice
	 * @return
	 */
	private static TradeWarSimpleNotice initTradeWarSimpleNotice(TradeWarNotice tradeWarNotice){
		TradeWarSimpleNotice data = new TradeWarSimpleNotice();
		data.setUserId(tradeWarNotice.getUserId());
		data.setEnemyUserId(tradeWarNotice.getEnemyUserId());
		data.setNoticeTime(tradeWarNotice.getNoticeTime());
		data.setKillPatronsCount(tradeWarNotice.getKillPatronsCount());
		return data;
	}

	/**
	 * 初始化公告msg
	 */
	private static void initTradeWarNoticeListMsg(){
		List<TradeWarNotice> tempList;
		synchronized (tradeWarNoticeList){
			tempList = new ArrayList<>(tradeWarNoticeList);
		}
		LinkedList<TradeWarNotice> resultList = new LinkedList<>();
		for(int i = tempList.size() - 1; i >= 0; i--){
			TradeWarNotice data = tempList.get(i);
			boolean isFind = false;
			if(data.getBattleType() == eTradeWarBattleType.Challenge.getValue()){
				for(TradeWarNotice loopData : resultList){
					if(loopData.getBattleType() == eTradeWarBattleType.Challenge.getValue() &&
							data.getUserId() == loopData.getUserId() &&
							data.getEnemyUserId() == loopData.getEnemyUserId()){
						isFind = true;
						break;
					}
				}
			}
			if(!isFind){
				calcTradeWarNoticeChallengeTimes(data);
				resultList.addFirst(data);
			}
		}
		tradeWarNoticeListMsg = TradeWarPb.parseTradeWarNoticeListMsg(resultList);
	}

	/**
	 * 计算公告战斗数量
	 * @param tradeWarNotice
	 */
	private static void calcTradeWarNoticeChallengeTimes(TradeWarNotice tradeWarNotice){
		int totalChallengeTimes = 0;
		int totalKillPatronsCount = 0;
		List<TradeWarSimpleNotice> tempList = getTradeWarSimpleNoticeList(tradeWarNotice.getUserId(), tradeWarNotice.getEnemyUserId());
		if(null != tempList) {
			totalChallengeTimes = tempList.size();
			for (TradeWarSimpleNotice simpleNotice : tempList) {
				totalKillPatronsCount += simpleNotice.getKillPatronsCount();
			}
		}
		tradeWarNotice.setTotalChallengeTimes(totalChallengeTimes);
		tradeWarNotice.setTotalKillPatronsCount(totalKillPatronsCount);
	}

	public static void buildWarTeamBattleTemp(TradeWarTeamProto.TradeWarTeamBattleRespMsg.Builder respMsg, BattleResult battleResult) {
		TradeWarTeamProto.TradeWarTeamBattleTempMsg.Builder resultMsg = TradeWarTeamProto.TradeWarTeamBattleTempMsg.newBuilder();
		resultMsg.setTeamIndex(battleResult.getTeamIndex());
		resultMsg.setKillPatronsCount(battleResult.getKillPatronsCount());
		resultMsg.setMyAddScore(battleResult.getMyAddScore());
		resultMsg.setEnemyLoseScore(battleResult.getEnemyLoseScore());
		resultMsg.setReward(battleResult.getReward());
		resultMsg.setEffectMammonSkill(battleResult.getEffectMammonSkill());
		resultMsg.setBattleTimes(battleResult.getWarTimes());
		PlayerProto.PlayerBaseTempMsg.Builder enemyMsg = PlayerBasePb.parsePlayerBaseTempMsg(UserMgr.getUserBaseInfo(battleResult.getEnemyUserId(), GameServer.getInstance().getServerId()));
		resultMsg.setEnemyBaseData(enemyMsg);
		respMsg.addBattleResult(resultMsg);
	}
}
